package com.example.dou2204.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.dou2204.R;
import com.example.dou2204.entity.BannerEntity;
import com.example.dou2204.entity.VideoEntity;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.List;

public class TuiVideoAdapter extends BaseMultiItemQuickAdapter<VideoEntity.DataBean, BaseViewHolder> {
    public TuiVideoAdapter(@Nullable List<VideoEntity.DataBean> data) {
        super(data);
        addItemType(0, R.layout.item_video_normal);//普通视频
        addItemType(1,R.layout.item_video_live);//直播视频
        addItemType(2,R.layout.item_video_quan);//全屏观看视频
        addItemType(5,R.layout.item_video_normal);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, VideoEntity.DataBean bean) {
        switch (bean.getItemType()){
            case 0:
            case 2:
            case 5:
            //代码块，可以有效防止自己记错名字
            {
                //修改视频播放器
                StandardGSYVideoPlayer gsy = holder.findView(R.id.gsy);
                gsy.setUp(bean.getVideopath(),true,"");
                gsy.getBackButton().setVisibility(View.GONE);//返回按钮不显示
                gsy.startPlayLogic();//实现播放
                //实现视频可横屏观看
                gsy.setShowFullAnimation(true);
                gsy.setAutoFullWithSize(false);
                gsy.setLockLand(true);
                //修改图片类的
                ImageView ivZhuan = holder.findView(R.id.iv_zhuan);
                ImageView ivUser = holder.findView(R.id.iv_user);
                Glide.with(getContext()).load(bean.getHeadpath()).circleCrop().into(ivZhuan);
                Glide.with(getContext()).load(bean.getHeadpath()).circleCrop().into(ivUser);
                //修改文字类的
                holder.setText(R.id.tv_dianzan,bean.getLike_count()+"");//点赞数量
                holder.setText(R.id.tv_address,bean.getAddress()+"");//地址
                holder.setText(R.id.tv_user, bean.getAuthname());//作者
                holder.setText(R.id.tv_caption, bean.getCaption());//标题
                holder.setText(R.id.tv_pao, bean.getAuthname()+"创作的原声音乐");
                //想让跑马灯动起来，需要获取焦点
                TextView tvPao = holder.findView(R.id.tv_pao);
                tvPao.requestFocus();
                //为了正确显示当前用户是否关注了博主
                ImageView ivAdd = holder.findView(R.id.iv_add);
                if(bean.getGuanzhu()==1){
                    ivAdd.setVisibility(View.GONE);//关注成功，关注图标不显示
                }else{
                    ivAdd.setVisibility(View.VISIBLE);
                }
                ImageView ivDianzan = holder.findView(R.id.iv_dianzan);
                if(bean.getDianzan()==1){
                    ivDianzan.setImageResource(R.drawable.ic_xihuanred);
                }else{
                    ivDianzan.setImageResource(R.drawable.ic_xihuan);
                }
            }
            break;
            case 1:
                //修改视频播放器
                StandardGSYVideoPlayer gsy = holder.findView(R.id.gsy);
                gsy.setUp(bean.getVideopath(),true,"");
                gsy.getBackButton().setVisibility(View.GONE);//返回按钮不显示
                gsy.startPlayLogic();//实现播放

                //修改文字类的
                holder.setText(R.id.tv_address,bean.getAddress()+"");
                holder.setText(R.id.tv_user, bean.getAuthname());
                holder.setText(R.id.tv_caption, bean.getCaption());
                holder.setText(R.id.tv_pao, bean.getAuthname()+"创作的原生音乐");
                //想让跑马灯动起来，需要获取焦点
                TextView tvPao = holder.findView(R.id.tv_pao);
                tvPao.requestFocus();
                break;

        }
    }
}
